// pages/delivery/delivery.js
Page({

    /**
     * 页面的初始数据
     */
    data: {

        token:"",

        Title:[ 
            {
                id:0,
                name:"快递点"
            },
            {
                id:1,
                name:"地点"
            },
            {
                id:2,
                name:"送达时间"
            },
            {
                id:3,
                name:"赏金"
            }
        ],

        delivery:[]

    },

    //接受订单上传token和orderId
    takeorder:function(e){
        var that=this
        console.log(that.data.test)
        wx.showModal({
          title:"接单",
          content:"是否接受订单",
          success(res){
              if(res.confirm){ 
                wx.request({
                    url: 'http://119.23.252.15:10002/delivery/receiveOrder',
                    method:"POST",
                    data:{
                        token : wx.getStorageSync('token'),
                        orderId : e.currentTarget.id
                    },
                    success(res){
                        if(res.data.status){
                        that.onLoad()
                        wx.showToast({
                          title: '成功接受订单',
                        })
                        }
                        else{
                            wx.showToast({
                              title: '接受订单失败 似乎出现了什么BUG',
                            })
                        }
                    }
                  })
              }
              else if (res.cancel)
              {
                  console.log('不接单')
              }
          },
          
        })
    },


    //发送token获取待接订单信息
    onLoad: function () {
        var that = this
        wx.request({
          url: 'http://119.23.252.15:10002/delivery/unreceiveOrderList',
          method:"POST",
          data:{
            token:wx.getStorageSync('token')
          },
          success(res){

            console.log(wx.getStorageSync('token'))
            console.log(res.data)

              that.setData({
                  delivery:res.data.data.unreceiveOrderList,
                  token:wx.getStorageSync({key:'token', success(){console.log("读取用户token失败")}})
              })
          }
        })
    },
})